//
//  RelateViewController.m
//  HimalayaMusic
//
//  Created by dllo on 16/1/15.
//  Copyright © 2016年 WXCLegendary. All rights reserved.
//

#import "RelateViewController.h"

@interface RelateViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)NSMutableArray *dataSource;
@property (nonatomic, strong)UITableView *tableView;
@end

@implementation RelateViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.view.backgroundColor = [UIColor whiteColor];

    [self getData];
    [self createTableView];
}

- (void)getData {
    self.dataSource = [NSMutableArray array];
    NSString *str = [NSString stringWithFormat:@"http://ar.ximalaya.com/rec-association/recommend/album/by_album?albumId=%@&device=android", self.albumID];
    [WXCNetWorkTool getWithUrl:str parameter:nil httpHeader:nil responseType:ResponseTypeJson success:^(id result) {
        for (NSDictionary *dic in result[@"albums"]) {
            RelateModel *relateModel = [[RelateModel alloc] initWithDictionary:dic];
            [self.dataSource addObject:relateModel];

        }
        [self.tableView reloadData];
    } fail:^(NSError *error) {
        
        
    }];

}

- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 64) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource =self;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[RelateTableViewCell class] forCellReuseIdentifier:@"reuse"];
    
    [self.view addSubview:self.tableView];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RelateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.relateModel = self.dataSource[indexPath.row];
    return cell;
    
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    return 80;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

//点击方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    AlbumViewController *albumVC = [[AlbumViewController alloc] init];
    albumVC.hotRecommendListModel = [[HotRecommendListModel alloc] init];
    albumVC.hotRecommendListModel.albumId = [self.dataSource[indexPath.row] albumId];
    [self.navigationController pushViewController:albumVC animated:YES];
    
    
    
}











- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
